package com.example.demo.service.impl;


import com.example.demo.mapper.BookMapper;
import com.example.demo.pojo.Book;
import com.example.demo.pojo.request.BaseRequest;
import com.example.demo.pojo.request.BookRequest;
import com.example.demo.pojo.request.UserPageRequest;
import com.example.demo.service.IBookService;
import com.example.demo.service.IuserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service
public class BookServiceImpl implements IBookService {
    @Autowired
    private BookMapper bookMapper;
    //查询全部
    @Override
    public List<Book> list() {
        List<Book> bookList = bookMapper.list();
        return bookList;
    }

    //分页查询
    @Override
    public PageInfo<Book> page(BookRequest bookRequest) {
        PageHelper.startPage(bookRequest.getPageNum(),bookRequest.getPageSize());
        List<Book> userList = bookMapper.page(bookRequest);
       return new PageInfo<>(userList);
    }

    //添加数据
    @Override
    public void save(Book Book) {
        Book.setCreateTime(new Date());
        bookMapper.save(Book);
    }

    //回写信息
    @Override
    public Book getUser(Integer id) {
         Book Book = bookMapper.getUser(id);
         return Book;
    }

    //更新数据
    @Override
    public void getIDUser(Book Book) {
        Book.setUpdateTime(new Date());
        bookMapper.getUserByID(Book);
    }

    //删除数据
    @Override
    public void delete(Integer id) {
        bookMapper.delete(id);
    }


}
